home *** CD-ROM | disk | FTP | other *** search
- /* This file contains a very incomplete implementation of the
- UNIX dirent routines for THINK C - Mac.
-
- This code is crap.
-
- You can only open the current directory.
- */
-
- /* Do NOT have the THINK C MacHeaders option checked-- include
- manually */
- #include <MacHeaders>
-
- #include <Pascal.h>
- #include <stdlib.h>
-
- #include "dirent.h"
- #include "string.h"
-
- #ifndef NULL
- #define NULL 0;
- #endif
-
- static HFileInfo myCPB; /* for the PBGetCatInfo call */
- static short int theIndex;
- static long int dirIDToSearch;
- static struct dirent mydirent;
-
-
- /* Only works for ".". And only one active call at a time */
- DIR *opendir(filename)
- char *filename;
- {
- if (strcmp(filename, ".") != 0) {
- SysBeep(1);
- return (void *) 0;
- }
-
- mydirent.d_fileno = 1L;
- *mydirent.d_name = '\0';
- myCPB.ioNamePtr = (void *) CtoPstr(mydirent.d_name);
- myCPB.ioVRefNum = 0;
- dirIDToSearch = 0L; /* Current one */
- theIndex = 1;
- return (DIR *)11;
-
- }
-
- closedir(dirp)
- DIR *dirp;
- {
-
- }
-
- struct dirent *readdir(dirp)
- DIR *dirp;
- {
- OSErr err;
-
- myCPB.ioFDirIndex= theIndex; /* set up the index */
-
- /* we need to do this every time through, since GetCatInfo returns
- ioFlNum in this field*/
- myCPB.ioDirID= dirIDToSearch;
-
- err= PBGetCatInfo(&myCPB,false);
-
- if (err != noErr) return NULL;
-
- PtoCstr(mydirent.d_name);
- mydirent.d_namlen = strlen(mydirent.d_name);
-
- theIndex++;
- return &mydirent;
- }
-